package com.shu.pattern;

/**
 * @author ssm
 * @version V1.0
 * @description: 责任链模式
 * @date 2021/8/18 17:28
 */

public class ChainRespPattern {

    public static void main(String[] args) {
        Handler leader = new Leader().setNextHandler(new Boss());
        leader.process(9);
        leader.process(10);
    }

}

class Leader extends Handler {

    @Override
    void process(Integer info) {
        if (info < 10) {
            System.out.println("Leader 处理");
        } else {
            this.nextHandler.process(info);
        }
    }
}


class Boss extends Handler {
    @Override
    void process(Integer info) {
        if (info >= 10) {
            System.out.println("Boss 处理");
        }
    }
}

abstract class Handler {
    protected Handler nextHandler;

    public Handler setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
        return this;
    }
    abstract void process(Integer info);
}
